home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CD32 / CD32_Support / examples / SA_Examples / nonvolatile / DeleteNV.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  2.6 KB  |  114 lines

  1. /* DeleteNV.c
  2.  * 
  3.  * test nonvolatile.library/DeleteNV()
  4.  * 
  5.  * 
  6.  */
  7.  
  8. /* Includes --------------------------------------------- */
  9. #include <exec/types.h>
  10. #include <exec/libraries.h>
  11. #include <exec/memory.h>
  12. #include <dos/dos.h>
  13. #include <dos/rdargs.h>
  14. #include <libraries/nonvolatile.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/nonvolatile_protos.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #include <pragmas/nonvolatile_pragmas.h>
  22.  
  23. #include "nv.h"         /* default app/item names, etc. */
  24.  
  25. /* Defines ------------------------------------------ */
  26. #define PROGNAME "DeleteNV"
  27. #define ERRMSG_LIBNOOPEN "Couldn't open %s V%ld (or better)!\n"
  28. #define TEMPLATE "NAME=APPNAME/K,ITEM=ITEMNAME/K,KILLREQ/S"
  29.  
  30.  
  31. /* Structs ------------------------------ */
  32. struct Opts {
  33.     STRPTR name;
  34.     STRPTR item;
  35.     LONG   killReq;
  36. };
  37.  
  38. /* Protos ------------------------------------------ */
  39. static VOID GoodBye(int);
  40. static LONG doInit(VOID);
  41.  
  42. /* Globals --------------------------------------- */
  43. struct Opts     opts;
  44. struct RDArgs  *rdargs;
  45. struct Library *NVBase;
  46.  
  47.  
  48. VOID main(int argc, UBYTE *argv[]) {
  49.     STRPTR app, item;
  50.     BOOL success, killReq;
  51.     LONG ioErr;
  52.     int rc = RETURN_OK;
  53.  
  54.     if (!doInit()) {
  55.         GoodBye(RETURN_FAIL);
  56.     }
  57.  
  58.     app  = ((opts.name) ? opts.name : (STRPTR)DEFAULT_APP_NAME);
  59.     item = ((opts.item) ? opts.item : (STRPTR)DEFAULT_ITEM_NAME);
  60.     killReq = ((opts.killReq) ? TRUE : FALSE);
  61.  
  62.     Printf("Calling DeleteNV(%s, %s)...\n", app, item);
  63.  
  64.     success = DeleteNV(app, item, killReq);
  65.     ioErr = IoErr();
  66.     if (!success) {
  67.         PutStr("DeleteNV returned failure.\n");
  68.         PrintFault(ioErr, PROGNAME);
  69.         rc = RETURN_ERROR;
  70.     }
  71.     else {
  72.         Printf("DeleteNV returned success.  IOErr was %ld  \n", ioErr);
  73.         PrintFault(ioErr, NULL);
  74.     }
  75.  
  76.     GoodBye(RETURN_OK);
  77. }
  78.  
  79. /* GoodBye ===============================================
  80.    Clean-exit routine.
  81.  */
  82. static VOID GoodBye(int rc) {
  83.     if (NVBase) {
  84.         CloseLibrary(NVBase);
  85.     }
  86.  
  87.     if (rdargs) {
  88.         FreeArgs(rdargs);
  89.     }
  90.  
  91.     exit(rc);
  92. }
  93.  
  94. /* doInit =============================================
  95.  * Open libraries, call ReadArgs() if necessary.
  96.  * Returns TRUE for success, FALSE otherwise.
  97.  */
  98. static LONG doInit(VOID) {
  99.     rdargs = ReadArgs(TEMPLATE, (LONG *)&opts, NULL);
  100.     if (!rdargs) {
  101.         PrintFault(IoErr(), PROGNAME);
  102.         return(FALSE);
  103.     }
  104.  
  105.     NVBase = OpenLibrary("nonvolatile.library", 40L);
  106.     if (!NVBase) {
  107.         Printf(ERRMSG_LIBNOOPEN, "nonvolatile.library", 40L);
  108.         return(FALSE);
  109.     }
  110.  
  111.     return(TRUE);
  112. }
  113.  
  114.